<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <script>
      /**
       * 策略模式：
       * **/
      // function performanceS(salary) {
      //   return salary * 4;
      // }

      // function performanceA(salary) {
      //   return salary * 3;
      // }

      // function performanceB(salary) {
      //   return salary * 2;
      // }

      // let calculateBonus = function (salary, level) {
      //   if (level === "S") {
      //     return performanceS(salary);
      //   } else if (level === "A") {
      //     return performanceA(salary);
      //   } else if (level === "B") {
      //     return performanceB(salary);
      //   }
      // };

      let strategy = {
        S: function (salary) {
          return salary * 4;
        },
        A: function (salary) {
          return salary * 3;
        },
        B: function (salary) {
          return salary * 2;
        },
      };

      let calculateBonus = function (salary, level) {
        return strategy[level](salary);
      };

      calculateBonus(10000, "S");
      calculateBonus(8000, "A");

      console.log(calculateBonus(10000, "S"));
      console.log(calculateBonus(8000, "A"));
    </script>
  </body>
</html>
